/**
 * @(#) ReqMedicalMoneyMediator.as
 *
 * @date		2011. 03. 28.
 * @version		1.0
 * @author		Baek, kwang hyoun
 * @description	의료비 신청 - Mediator
 * 				의료비를 신청하는 Presentation Logic을 관리 
 */
package com.skt.common_hr.medicalmoney.view
{
	import com.skt.common_hr.common.Variables;
	import com.skt.common_hr.common.approval.RequestApprovalMediator;
	import com.skt.common_hr.common.components.CommonAlert;
	import com.skt.common_hr.common.puremvc.CommonMediator;
	import com.skt.common_hr.common.utilSilver.textSilver;
	import com.skt.common_hr.medicalmoney.MedicalMoneyFacade;
	import com.skt.common_hr.medicalmoney.events.MedicalMoneyEvent;
	import com.skt.common_hr.medicalmoney.model.*;
	import com.skt.common_hr.medicalmoney.model.vo.MedicalMoneyVO;
	import com.skt.common_hr.medicalmoney.model.vo.MedicalMoneyWriteVO;
	import com.skt.common_hr.medicalmoney.model.vo.MedicalSubTabVO;
	import com.skt.common_hr.medicalmoney.view.components.ReqMedicalMoneyView;
	import com.wcl.utils.ArrayHelper;
	import com.wcl.utils.DateUtil;
	import com.wcl.utils.NumberUtil;
	
	import flash.events.Event;
	
	import mx.collections.ArrayCollection;
	
	import org.puremvc.as3.multicore.interfaces.INotification;

	public class ReqMedicalMoneyMediator extends CommonMediator
	{
		public static const NAME:String = "MidicalMoneyWriteMediator";
		
		public static const CLOSED_REQUEST_VIEW:String	= "closedRequestView";
 		private var bWaitingApproval:Boolean = false;
 		private var bWaitingExistData:Boolean = false;
		private var _currentKey:String = "";

		
		/**
		* 생성자
		* 
		* @param
		* @return void
		*/
        public function ReqMedicalMoneyMediator( viewComponent:Object )
        {
            super( NAME, viewComponent );
        }
 		
		/**
		* View를 초기화 한다.
		*	- View에 기본사항을 출력하고 data를 load
		* @param
		* @return void
		*/
 		override protected function initializeView():void
 		{
 			setEventListeners();
 		}
 		
 		private function setEventListeners():void
 		{
 			// 신청창에서 리스트창으로 
 			view.addEventListener(ReqMedicalMoneyView.MedicalWriteClose, goMainList);
 			view.addEventListener(MedicalMoneyFacade.SAVE_MEDICALMONEY_REQUEST, onSaveRequest);
 			view.addEventListener(MedicalMoneyFacade.LOAD_MM_CHG_YEAR_CB, onChgCbLoadMedicalMoneyLimitData);
 			
 			view.addEventListener(MedicalMoneyFacade.APPROVAL_REQUEST, onApprovalRequest);
 			
 			
 			 			
/* 			view.addEventListener(ReqCelebrationView.CongStandard, displaySupportStandard);
			view.addEventListener(ReqCelebrationView.CongCpernrChange, onClickSelectMember);
			view.addEventListener(ReqCelebrationView.CongAccount, onCongAccount);
			view.addEventListener(ReqCelebrationView.CongFamilySelect, onClickChangeFamily);
			
			//view.addEventListener(ComboBoxEvent.SELECT_DATA, onChangedCode);
			view.addEventListener(ReqCelebrationView.CHANGED_CELEBRRATION_CODE, onChangedCelebrationCode);
			
			//view.addEventListener(CongMoneyWriteEvent.UPDATE_DATA, onCongMoneyWriteUpdate);
			view.addEventListener(ReqCelebrationView.CongClose, onCongClose);
			
			// 경조일 선택시
			view.addEventListener(ReqCelebrationView.CongDaySelect, onCongDaySelect);
			
			// 경조휴가 가능일
			view.addEventListener(ReqCelebrationView.CongDayVocationCheck, onCongDayVocationCheck); */
 		}

 		private function removeEventListener():void
 		{
 			// 신청창에서 리스트창으로 
 			view.removeEventListener(ReqMedicalMoneyView.MedicalWriteClose, goMainList); 	
 			view.removeEventListener(MedicalMoneyFacade.SAVE_MEDICALMONEY_REQUEST, onSaveRequest);
 			view.removeEventListener(MedicalMoneyFacade.LOAD_MM_CHG_YEAR_CB, onChgCbLoadMedicalMoneyLimitData);
 			view.removeEventListener(MedicalMoneyFacade.APPROVAL_REQUEST, onApprovalRequest);		
 		} 		


 		/**
		 * 입력으로 돌아가기
		 * @param
		 * @return void
		 */
 		private function goMainList(event:Event):void
 		{
 			clearView();
 			bActivated = false;
 			facade.sendNotification(CLOSED_REQUEST_VIEW, this);
 		}
 		 		
 		override protected function clearView():void
 		{
 			trace("clear WriteMediator");
 			//view.dataProvider = null;
 			//view._medicalData = null;
 			//view.current_medical = null;
 		}
 		
  			
 		
 		
 		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Process MVC Messages
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		* 본 Class에서 처리해야할 Noti들을 등록한다.
		* 
		* @param
		* @return void
		*/
		override public function listNotificationInterests():Array 
		{
			return [
					MedicalMoneyFacade.LOAD_VALIDREQDAYRESULT_COMPLETE,
					MedicalMoneyFacade.LOAD_MEDICALMONEY_BANKA_COMPLETE,
					MedicalMoneyFacade.LOAD_MEDICALMONEY_WRITE_INITIAL,
					MedicalMoneyFacade.LOAD_MM_LIMIT_DATA_COMPLETE,
					MedicalMoneyFacade.LOAD_MM_LIMIT_DATA_FAILED,
					MedicalMoneyFacade.LOAD_MEDI_TITLE_COMPLETE,					
					MedicalMoneyFacade.SAVE_MEDICALMONEY_COMPLETE,
					MedicalMoneyFacade.SAVE_MEDICALMONEY_FAILED,
					MedicalMoneyFacade.LOAD_MEDICALMONEY_DETAIL_COMPLETE,
					MedicalMoneyFacade.LOAD_MEDICALMONEY_DETAIL_FAILED,					
					RequestApprovalMediator.APPROVAL_CANCEL,
					RequestApprovalMediator.APPROVAL_COMPLETE,					
					/* 

					CelebrationFacade.LOAD_CONGMONEY_WRITE_COMPLETE,
					CelebrationFacade.SAVE_CELEBRATION_COMPLETE,
					CelebrationFacade.SAVE_CELEBRATION_FAILED,
					
					CelebrationFacade.LOAD_FAMILY_INFO,
					CelebrationFacade.LOAD_CELEBRATION_CODE_COMPLETE,
					CelebrationFacade.LOAD_CELEBRATION_CODE_FAILED,
					
					CelebrationFacade.LOAD_CONGMONEY_BANKA_FAILED,
					CelebrationFacade.LOAD_FAMILY_COMPLETE,
					CelebrationFacade.LOAD_FAMILY_FAILED,
					CelebrationFacade.LOAD_CONGMONEY_SELECTED_COMPLETE,
					CelebrationFacade.LOAD_CONGMONEY_SAVE_FAILED,
					CelebrationFacade.LOAD_DEFAULT_FAMILY_FAILED,
					CelebrationFacade.LOAD_CONGMONEY_CORSNMONEY_COMPLETE,
					CelebrationFacade.LOAD_CONGMONEY_CORSNMONEY_FAILED,
					CelebrationFacade.SELECTED_FAMILY,
					CelebrationFacade.MODIFIED_ACCOUNT, 
					MemberSelectorMediator.SELECTED_MEMBER,

					
					CelebrationCodeProxy.LOAD_CONGDAYVALIDATE_COMPLETE,
					CelebrationCodeProxy.LOAD_CONGDAYVALIDATE_FAILED,
					CelebrationCodeProxy.LOAD_CONGDAY_VOCATION_CHECK_COMPLETE,
					CelebrationCodeProxy.LOAD_CONGDAY_VOCATION_CHECK_FAILED,
					*/
					//CelebrationFacade.LOAD_CONGMONEY_WRITE_INITCEHCK
					];
		}
		

		/**
		* Noti별로 처리한다.
		* 
		* @param
		* @return void
		*/
		override public function handleNotification(note:INotification):void
		{
			switch(note.getName()) 
			{
				
				// 신청 가능일 가능할때
				case MedicalMoneyFacade.LOAD_VALIDREQDAYRESULT_COMPLETE:
					commonSave2();
					break;
									
				// 초기 로딩시..
				case MedicalMoneyFacade.LOAD_MEDICALMONEY_WRITE_INITIAL:
					bActivated = true;
					view.dataProvider.WSTATUS = "";
					view.currentState = "stateView";	
					// 수정모드라면 입력폼 활성화.
					var t:Object = note.getBody(); 	
					if(t.write == true) {
						view.bWrite = true;
					} else {
						view.bWrite = false;
					}
					
					if(t.mode == 'new') {
						view.bMode = true;
					} else {
						view.bMode = false;
					}
								
					loadInitialData(note.getBody().pernr, note.getBody().name, note.getBody().gwarekey);
					break;
				// 계좌정보 
				case MedicalMoneyFacade.LOAD_MEDICALMONEY_BANKA_COMPLETE:
					setBankList(note.getBody() as AccountProxy);
					break;
					
				case MedicalMoneyFacade.LOAD_MM_LIMIT_DATA_COMPLETE:
					LitmitDateSetting(note.getBody() as ReqMedicalMoneyWriteProxy);
					break;						
				case MedicalMoneyFacade.LOAD_MM_LIMIT_DATA_FAILED:
					trace("MedicalMoneyFacade.LOAD_MM_LIMIT_DATA_FAILED");
					break;					

				case MedicalMoneyFacade.LOAD_MEDI_TITLE_COMPLETE:
					mediTitleSetting(note.getBody() as ReqMedicalMoneyWriteProxy);
					break;					

												
				case MedicalMoneyFacade.SAVE_MEDICALMONEY_COMPLETE:
					// 승인요청하여 결재창이 뜨도록. 
					if(bWaitingApproval) {
						_currentKey = MedicalMoneyProxy(note.getBody()).key; 
						view.dataProvider.GWAREKEY = parseInt(_currentKey);
						execApproval(_currentKey);
						
						completeMedicalMoney(note.getBody());
					}
					else {								
						completeMedicalMoney(note.getBody()); 
						facade.sendNotification(CLOSED_REQUEST_VIEW, this);
					}
					bWaitingApproval = false;
					break;																

				case MedicalMoneyFacade.SAVE_MEDICALMONEY_FAILED:
					bWaitingApproval = false;
					CommonAlert.showMessage(commonFacade.bundle, MedicalMoneyProxy(note.getBody()).faultMessage, null);
					break;
					
				case MedicalMoneyFacade.LOAD_MEDICALMONEY_DETAIL_COMPLETE:
					if(bActivated) {
						setLoadedDetailInfo( MedicalMoneyProxy(note.getBody()) );
					}
					break;
					
				case MedicalMoneyFacade.LOAD_MEDICALMONEY_DETAIL_FAILED:
					trace("LoadCongmoneyWriteFailed");
					break;
					
				// 결재 요청  성공	
				case RequestApprovalMediator.APPROVAL_COMPLETE:					
					bActivated = false;
		 			clearView();
		 			facade.sendNotification(CLOSED_REQUEST_VIEW, this);
					//facade.sendNotification(TrainingFacade.SUCCEED_REQ_TRAINING, this);
					break;
				
				// 결재 요청 취소	
				case RequestApprovalMediator.APPROVAL_CANCEL:					
					bActivated = true;
		 			//clearView();
		 			//facade.sendNotification(CLOSED_REQUEST_VIEW, this);
					//cancelApproval(_currentKey);
					break;
															
				/*
				case CelebrationFacade.SAVE_CELEBRATION_COMPLETE:
					//setStatusMessage("저장되었습니다.");
					if(bWaitingApproval) {
						_currentKey = CelebrationProxy(note.getBody()).key; 
						view.dataProvider.GWAREKEY = _currentKey;
						execApproval(_currentKey);
					}
					else {
			 			clearView();
 						bActivated = false;
			 			facade.sendNotification(CLOSED_REQUEST_VIEW, this);
			 		}
			 		bWaitingApproval = false;
					trace("saved completed");
					break;

				case CelebrationFacade.LOAD_CELEBRATION_CODE_COMPLETE:
					setCelebrationCode(CelebrationCodeProxy(note.getBody()).codeList); 
					break;
				case CelebrationFacade.LOAD_CELEBRATION_CODE_FAILED:
					//setStatusMessage("경조사유코드를 조회중 오류가 발생했습니다.");
					break;
				case CelebrationFacade.LOAD_FAMILY_COMPLETE:
					setFamilyList(FamilyProxy(note.getBody()).family); 
					break;
				case CelebrationFacade.LOAD_FAMILY_FAILED:
					//setStatusMessage("가족정보를 조회중 오류가 발생했습니다.");
					break;

				case CelebrationFacade.LOAD_CONGMONEY_BANKA_FAILED:
					trace("LoadCongmoneyBankaFailed");
					//AlertHelper.showMessage((note.getBody() as CongMoneyWriteProxy).bnksaFaultMessage);
					break;

				case CelebrationFacade.SELECTED_FAMILY:
					onFamilyDataLoad(note.getBody() as CongFamilyVO);
					break;
				case MemberSelectorMediator.SELECTED_MEMBER:
					if(bActivated) {
						onMemberDataLoad(MemberSelectorMediator(note.getBody()).selectedMember);
					}
					break;
					
				case CelebrationFacade.MODIFIED_ACCOUNT:
					//기타계좌 수정시 계좌관리  로드 
 					//bankaLoadData();
 					//loadBankInfo(view.dataProvider.CPERNR);
 					var subMedi:CongMoneyAccountMediator = facade.retrieveMediator(CongMoneyAccountMediator.NAME) as CongMoneyAccountMediator;
 					view.dataProvider.BANKL = subMedi.BANKL;
					view.dataProvider.BANKA = subMedi.BANKA;
 					view.dataProvider.BANKN = subMedi.BANKN;
 					view.dataProvider.EMFTX = subMedi.EMFTX;
 					var index:int = ArrayHelper.indexOf(view.accounts, "BNKSA", 2); 
					if(index>0) {
						var selectedAccount:CongMoneyAccountVO = view.accounts[index];
						selectedAccount.BANKL = subMedi.BANKL;
						selectedAccount.BANKA = subMedi.BANKA;
						selectedAccount.BANKN = subMedi.BANKN;
						selectedAccount.EMFTX = subMedi.EMFTX; 
					}
					trace(view.dataProvider.BANKA, view.dataProvider.BANKN,view.dataProvider.EMFTX );
					break;
					
				case CelebrationFacade.LOAD_CONGMONEY_SELECTED_COMPLETE:
					onSelected(note.getBody() as CelebrationProxy);
					break;
				case CelebrationFacade.LOAD_CONGMONEY_SAVE_FAILED:
					//경조신청 저장시 휴가중복일경우
					onSaveErroryMessage(note.getBody() as CongMoneyWriteProxy);
					break;
				
				case CelebrationFacade.LOAD_DEFAULT_FAMILY_FAILED:
					trace("LoadDefaultFamilyFailed");
					CommonAlert.showMessage(commonFacade.bundle, (note.getBody() as FamilyProxy).defaultResultMessage);
					break;
				case CelebrationFacade.LOAD_CONGMONEY_CORSNMONEY_COMPLETE:
					//onCorsnMoney(note.getBody() as CongMoneyWriteProxy);
					break;
				case CelebrationFacade.LOAD_CONGMONEY_CORSNMONEY_FAILED:
					CommonAlert.showMessage(commonFacade.bundle, (note.getBody() as CongMoneyWriteProxy).corsnMoneyResultMessage);
					view.BETRG.text = "0";
 					view.ZWRTH.selectedValue = "";
					break;
					
				case CelebrationFacade.LOAD_CONGMONEY_WRITE_INITCEHCK:
					//대상자 변경 가능 유무 및 기간 셋팅.
					onInitCheck(note.getBody());
					break;

				case CelebrationCodeProxy.LOAD_CONGDAYVALIDATE_COMPLETE:	
					onCongDaySelectHandler(note.getBody());
					break;
					
				case CelebrationCodeProxy.LOAD_CONGDAY_VOCATION_CHECK_COMPLETE:	
					onCongDayVocationCheckHandler(note.getBody());
					break;					
						 */				
				default:
					//trace(this.instanceID+"에서 처리 안된 Noti가 검출됨 : " + note.getBody());
					break;
			}
		}
		
		/**
		 * Proxy에서 DataLoad를 완료한 후 호출됨
		 *     - 조회상세보기
		 * @param
		 * @return void
		 */
 		private function setLoadedDetailInfo(voWrapObj:MedicalMoneyProxy):void
 		{
 			var vo:MedicalMoneyVO = voWrapObj.detailVO;
 			_currentKey = vo.GWAREKEY.toString();
 			
			view.dataProvider = vo;
			view.migrationHowMuch = NumberUtil.NumberFormat(vo.HOWMUCH).toString();
			view.medicalData = voWrapObj.subTabList;
			
			var sTargetDate:String = vo.SPMON;

			view.cbMediTitle.dataProvider = voWrapObj.acMediTitle;
	 		loadBankInfo(Variables.myPernr);
 			loadMedicalMoneyLimitData(Variables.myPernr, sTargetDate, vo.GWAREKEY.toString(), vo.MEDI);	//의료비 마감일자와 의료비 지원가능금액 산출
 			
 			
 			setMediCombo(voWrapObj.sMediTitleSelectedCode);
 			
			// 마이그레이션 해온 지난 데이타일 경우에..				
//			if(view.medicalData.length == 0) {
//				view.lbApplyMoney.text = view.migrationHowMuch;
//			}							 			
 		} 
		
		public function setMediCombo(sCode:String):void {
			var ac:ArrayCollection = view.cbMediTitle.dataProvider as ArrayCollection;
			var sIndex:uint = ArrayHelper.indexOf(ac, 'CODE', sCode);
			view.cbMediTitle.selectedIndex = sIndex;
		}
		
		/**
		 * Proxy에서 DataLoad를 완료한 후 호출됨
		 *     - 계좌선택 콤보 load된 데이터를 화면에 출력
		 * @param
		 * @return void
		 */
 		private function setBankList(proxy:AccountProxy):void
 		{
 			view.accounts = proxy.AccountList;
 			
 			if(bWaitingExistData) {
				 				
 			}
 			else {
 				//view.clearAccountInfo();
 			}
 			bWaitingExistData = false;
 		}

		/**
		 * MedicalMoney 저장 완료한 후 호출됨
		 *     
		 * @param
		 * @return void
		 */
		
		
 		private function completeMedicalMoney(val:Object):void
 		{
 			_currentKey = val.key;
 			
 			
 			//AlertHelper.showMessage("임시저장이 완료되었습니다.");

/* 
 			if(view.sSaveGubun == "X") {
 				//AlertHelper.showMessage("승인요청이 완료되었습니다.");
 				facade.sendNotification(ReqMedicalMoneyMediator.CLOSED_REQUEST_VIEW, this);
 				
 			} else {
 				AlertHelper.showMessage("임시저장이 완료되었습니다."); 				
 			}
 */ 			
 		} 				
		
		
		/**
		 * Proxy에서 DataLoad를 완료한 후 호출됨
		 * 마감일과 가용금액셋팅 
		 * @param
		 * @return void
		 */
 		private function LitmitDateSetting(proxy:ReqMedicalMoneyWriteProxy):void
 		{
 			//view.accounts = proxy.mmLimitDateLoadList;
 			// 왜 setter를 썼을지..모르겠음. 난 그냥 함수로 씀.
 			view.LitmitDateSetting(proxy.mmLimitDateLoadList);
 			
 			if(bWaitingExistData) {
				 				
 			}
 			else {
 				//view.clearAccountInfo();
 			}
 			bWaitingExistData = false;
 		} 				

		
		/**
		 * 진료과목 셋팅
		 * @param
		 * @return void
		 */
 		private function mediTitleSetting(proxy:ReqMedicalMoneyWriteProxy):void
 		{
 			view.cbMediTitle.dataProvider =  proxy.acMediTitle;
 			loadMedicalMoneyLimitData(Variables.myPernr, null, "" );	//의료비 마감일자와 의료비 지원가능금액 산출
 		}

 				
		private function findCodeIndex(key:String, srcArr:ArrayCollection):int 
		{
			for(var i:int=0; i<srcArr.length; i++) {
				if(srcArr[i].data == key) {
					return i;
				}
			}
			return -1;
		} 
		
		private function loadInitialData(pernr:String, name:String, gwarekey:String=""):void
		{
			view._medicalData = new ArrayCollection();
			_currentKey = ""; // 현재 키 초기화 
			
 			if(gwarekey!="") {
 				trace("modify data: " + gwarekey);
 				loadExistData(gwarekey);				//의료비 신청(입력,업데이트)
 				// 수정시 또는 view시에 진료과목 셋팅은 그 후에 셋팅			
 			}
 			else {
 				view.writeDefaultSetting(); 				 			
		 		loadBankInfo(Variables.myPernr);
	 			// 진료과목 셋팅
				loadMedTitle(); 			 		
				//loadMedicalMoneyLimitData은 loadMedTitle();이 끝나고 불름 				 			 			 				
 			}
		
			
		}
		
 		private function getDefaultData():MedicalMoneyWriteVO
 		{
 			var dp:MedicalMoneyWriteVO = new MedicalMoneyWriteVO;
 			dp.IPERNR = dp.CPERNR = Variables.myPernr;
 			dp.INAME = dp.CNAME = Variables.myName;
 			dp.CODAT = DateUtil.todayNoTime();
 			dp.IDATE = DateUtil.todayNoTime();
 			dp.COSEL = "X";
 			dp.WAERS = "KRW";
 			
 			return dp;
 		}	
		

		private function onChgCbLoadMedicalMoneyLimitData(e:Event):void {
			var sYear:String = view.cbApplyDateYear.selectedLabel;
			var sMonth:String = view.cbApplyDateMonth.selectedLabel;
			
			loadMedicalMoneyLimitData(Variables.myPernr, sYear+sMonth,_currentKey);	//의료비 마감일자와 의료비 지원가능금액 산출
		}

		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Access Functions....
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////

		private function execApproval(key:String):void
		{
 			var approval:RequestApprovalMediator = facade.retrieveMediator(RequestApprovalMediator.NAME) as RequestApprovalMediator;
 			if(approval==null) {
 				approval = new RequestApprovalMediator(view, "11");
 				facade.registerMediator(approval);
 			}
 			bActivated = false;
 			var appProxy:MedicalMoneyApprovalProxy = facade.retrieveProxy(MedicalMoneyApprovalProxy.NAME) as MedicalMoneyApprovalProxy;
 			appProxy.key = key;
 			appProxy.dataProvider = tmpVO; 
 			appProxy.acDataProvider2 = view._medicalData;
 			
 			approval.execRequest(view, appProxy);
		}


		
 		private function loadExistData(gwarekey:String):void
 		{
			var proxy:MedicalMoneyProxy = facade.retrieveProxy(MedicalMoneyProxy.NAME) as MedicalMoneyProxy;
			bWaitingExistData = true;
			proxy.loadDetail(gwarekey);
 		}

 		/**
		 * 의료비 마감일자, 한도 조회
		 * @param
		 * @return void
		 */
 		private function loadMedicalMoneyLimitData(pernr:String, tagetDate:String=null, gwarekey:String="", medi:String=""):void
 		{
 			
			var proxy:ReqMedicalMoneyWriteProxy = facade.retrieveProxy(ReqMedicalMoneyWriteProxy.NAME) as ReqMedicalMoneyWriteProxy;
			if(medi != '') {
				proxy.loadMmLimitData(pernr, tagetDate, gwarekey, medi); 				
 			} else {
 				proxy.loadMmLimitData(pernr, tagetDate, gwarekey, view.cbMediTitle.selectedItem.CODE);
 			}
 		} 		
 		
 		/**
		 * 경조사유 조회
		 * @param
		 * @return void
		
 		private function loadCodes(oneself:Boolean = true):void
 		{
			var proxy:MedicalMoneyProxy = facade.retrieveProxy(MedicalMoneyProxy.NAME) as MedicalMoneyProxy;
			//proxy.loadCodes( oneself ? "" : "X");
 		}
 		 */
 		
 		

 		/**
		 * 진료과목
		 * @param
		 * @return void
		* */
 		private function loadMedTitle():void
 		{
			var proxy:ReqMedicalMoneyWriteProxy = facade.retrieveProxy(ReqMedicalMoneyWriteProxy.NAME) as ReqMedicalMoneyWriteProxy;
			proxy.loadMediTitle();
			
 		}
 		
 		 		
 		/**
		 * 계좌선택 콤보
		 * @param
		 * @return void
		* */
 		private function loadBankInfo(pernr:String):void
 		{
			var accountProxy:AccountProxy = facade.retrieveProxy(AccountProxy.NAME) as AccountProxy;
			accountProxy.loadAccounts(pernr);
 		}
 		
 		 
  		/**
		 * 가족사항 조회
		 * @param
		 * @return void
		 
 		private function loadFamilyList(pernr:String):void
 		{
			var proxy:FamilyProxy = facade.retrieveProxy(FamilyProxy.NAME) as FamilyProxy;
			proxy.load(pernr);
 		}
		*/
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event handler (from View, Internal or....)
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
  		
 		/**
		 * 경조사 지원기준
		 * @param
		 * @return void
		
 		private function displaySupportStandard(event:Event):void
 		{
 			var proxy:SupportStandardProxy = facade.retrieveProxy(SupportStandardProxy.NAME) as SupportStandardProxy;
 			
 			var congStandardView:IFlexDisplayObject = PopUpManager.createPopUp(view, SupportStandard, true);
 			PopUpManager.centerPopUp(congStandardView);
 			(congStandardView as SupportStandard).setFocus();
 			SupportStandard(congStandardView).standardList = proxy.standardList;
 		}
 		 */
 		// 임시저장 		
 		private function onSaveRequest(event:Event):void 
 		{
 			bWaitingApproval = false;
			commonSave();
 		}

 		// 승인 요청
		private var tmpVO:MedicalMoneyVO; 		 
 		private function onApprovalRequest(event:MedicalMoneyEvent):void
 		{
 			bWaitingApproval = true;
 			//tmpVO = view.dataProvider;
 			tmpVO = event.writeVo;
 			
 			commonSave();
 		}  	

 		// 가능한 신청일 체크  	
 		private function commonSave():void {
			var sTargetDate:String = view.cbApplyDateYear.selectedLabel.toString() + view.cbApplyDateMonth.selectedLabel.toString()+"01"; 			
			var sNowDate:String = DateUtil.toBasicString(DateUtil.firstDateofThisMonth());
			var oProxy:ReqMedicalMoneyWriteProxy = facade.retrieveProxy(ReqMedicalMoneyWriteProxy.NAME) as ReqMedicalMoneyWriteProxy;
			oProxy.validReqDay(sTargetDate, sNowDate); 			
 		}
 		
 		private function commonSave2():void {
	 		// import
			var I_GWAREKEY:String 	= _currentKey;
			var I_REQUEST:String	= "";
			
			
			 			 
			// table 
			//ITAB
			var tItabArr:Array = new Array();
			var oItab:Object = new Object;			
			oItab.GWAREKEY	= I_GWAREKEY;
			oItab.PERNR		= Variables.myPernr;
			oItab.ENAME		= Variables.myName;
			
			oItab.SPMON		= view.cbApplyDateYear.selectedLabel.toString() + view.cbApplyDateMonth.selectedLabel.toString() ; 
			oItab.HOWMANY	= view.totalCnt;
			oItab.HOWMUCH	= textSilver.moneyTextToInt(view.lbApplyMoney.text)/100;
			
			//oItab.WSTATUS // 결재 진행상태
			//oItab.WSTATX	//결재진행상태 텍스트
			
			oItab.BANKS	= view.selectedAccount.BANKS;
			oItab.BANKL	= view.selectedAccount.BANKL;
			oItab.BANKA	= view.selectedAccount.BANKA;
			oItab.BNKSA	= view.selectedAccount.BNKSA;
			oItab.BANKN	= view.selectedAccount.BANKN;
			oItab.EMFTX	= view.selectedAccount.EMFTX;		
			oItab.STEXT	= "";
			
			oItab.WSTATUS= view.dataProvider.WSTATUS;
			
			// 진료과목 
			oItab.MEDI	= view.cbMediTitle.selectedItem.CODE;
			oItab.MEDIT	= view.cbMediTitle.selectedItem.TEXT;
			
			view.dataProvider.MEDI = oItab.MEDI; 
			view.dataProvider.MEDIT = oItab.MEDIT;
						
			tItabArr.push(oItab);
			
						
			// SUB_TAB
 			var tSub_tabArr:Array = new Array();
	 		for each(var rec:MedicalSubTabVO in view.medicalData)
	 		{
	 			var data:Object = new Object;
	 			data.USEDT = DateUtil.toBasicString(rec.USEDT);
	 			data.HOSPD = rec.HOSPD;
	 			data.BETRG = rec.BETRG/100;
	 			
	 			tSub_tabArr.push(data);  
	 		}
				 		 			
 			var proxy:MedicalMoneyProxy = facade.retrieveProxy(MedicalMoneyProxy.NAME) as MedicalMoneyProxy;
 			proxy.save(I_GWAREKEY, I_REQUEST, tItabArr, tSub_tabArr); 			
 		}
 		
 		/**
		 * 경조사 저장수정
		 * @param
		 * @return void
		 */
		 /* 
 		private function onCongMoneyWriteUpdate(event:CongMoneyWriteEvent):void
 		{
 			//facade.removeMediator(CongMoneyWriteMediator.NAME);
 			var proxy:CongMoneyWriteProxy = facade.retrieveProxy(CongMoneyWriteProxy.NAME) as CongMoneyWriteProxy;
 			proxy.update(event.Fkey, event.writeVo);
 		}
 		 */
 		/**
		 * 경조사 입력팝업닫기
		 * @param
		 * @return void
		 */
 		private function onCongClose(event:Event):void
 		{
 			clearView();
 			bActivated = false;
 			facade.sendNotification(CLOSED_REQUEST_VIEW, this);
 		}
 		 
 		 //의료비 상세보기 조회
 		private function onSelected(proxy:MedicalMoneyProxy):void
 		{
 			var congProxy:ReqMedicalMoneyWriteProxy = facade.retrieveProxy(ReqMedicalMoneyWriteProxy.NAME) as ReqMedicalMoneyWriteProxy;
			congProxy.load(proxy.key);
			
 			//corsnLoadData();
 			//bankaLoadData();
 		}
 		
 		//저장에러 메세지 휴가중복메세지
 		private function onSaveErroryMessage(proxy:ReqMedicalMoneyWriteProxy):void
 		{
 			//AlertHelper.showMessage(proxy.saveErroryMessage);
 		}
 		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Utility Functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
        private function get view():ReqMedicalMoneyView
        {
            return viewComponent as ReqMedicalMoneyView;
        }
		
		
	}
}